//
//  SSMainController.swift
//  Weibo
//
//  Created by vn on 16/7/19.
//  Copyright © 2016年 vn. All rights reserved.
//

import UIKit

class SSMainController: UITabBarController {
     override func viewDidLoad() {
        super.viewDidLoad()
        
         let table = SSTabBarView()
        
        //加号按钮的点击
        table.closure = {
            
            print("加号按钮点击了")
            
            
        }
        
        //tabBar是只读属性,要用KVC赋值
        setValue(table, forKey: "tabBar")
        
        addChildViewController(SSHomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(SSDiscoverController(), title: "发现", imageName: "tabbar_message_center")
        addChildViewController(SSMessageController(), title: "消息", imageName: "tabbar_profile")
        addChildViewController(SSMeController(), title: "我", imageName: "tabbar_discover")
         
    }
    
    //初始化控制器
    func addChildViewController(vc :UIViewController,title:String,imageName:String){
        
        //设置tabBarTitle
        vc.tabBarItem.title = title
        //设置NavTitle
        vc.title = title
        
        //设置默认图片
        vc.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中状态图片
        vc.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置字体颜色
        vc.tabBarItem .setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加到导航tabBar控制器上
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
    }
    
   
}
